package com.schematic.flixel.donquicoco
{
	import flash.display.Sprite;
	
	import org.flixel.FlxG;
	import org.flixel.FlxObject;
	import org.flixel.FlxSprite;
	
	/**
	 * Base class for Mario and Barrel
	 */
	public class BaseSprite extends FlxSprite
	{
		
	//--------------------------------------------------------------------------
	//
	//  Constants
	//
	//--------------------------------------------------------------------------
	
	//----------------------------------
	//  STOP_MOVING
	//----------------------------------
	/**
	 * String used to define the stop moving animation
	 */
	public static const STOP_MOVING:String = "stopMoving";
	
	//----------------------------------
	//  MOVE_LEFT
	//----------------------------------
	/**
	 * String used to define the move left animation
	 */
	public static const MOVE_LEFT:String = "moveLeft";
	
	//----------------------------------
	//  MOVE_RIGHT
	//----------------------------------
	/**
	 * String used to defined the move right animation
	 */
	public static const MOVE_RIGHT:String = "moveRight";
	
	//----------------------------------
	//  MOVE_UP
	//----------------------------------
	/**
	 * String used to define the move up animation
	 */
	public static const MOVE_UP:String = "moveUp";
	
	//----------------------------------
	//  MOVE_DOWN
	//----------------------------------
	/**
	 * String used to define the move down animation
	 */
	public static const MOVE_DOWN:String = "moveDown";
	
	//----------------------------------
	//  MOVE_DOWN
	//----------------------------------
	/**
	 * String used to define the move down animation
	 */
	public static const FALL:String = "fall";

    //----------------------------------
    //  PAUSE_ON_LADDER
    //----------------------------------
    /**
     * Pauses on a ladder
     */
    public static const PAUSE_ON_LADDER:String = "pauseOnLadder";
	

    //--------------------------------------------------------------------------
	//
	// Constructor
	//
	//--------------------------------------------------------------------------
	
	/**
	 * Creates a new <code>BaseSprite</code> instance.
	 */
	public function BaseSprite(x:Number = 0, y:Number = 0)
	{
		super(x, y);
	}
	
	//--------------------------------------------------------------------------
	//
	//  Properties
	//
	//--------------------------------------------------------------------------


    //----------------------------------
    //  direction
    //----------------------------------
    /**
     *  @private
     */
    private var _direction:int;

    /**
     * The current motion direction
     */
    public function get direction():int
    {
        return _direction;
    }	

    //----------------------------------
    //  lastDirection
    //----------------------------------
    /**
     *  @private
     */
    private var _lastDirection:int = -1;

    /**
     * The last direction before stop or fall
     */
    public function get lastDirection():int
    {
        return _lastDirection;
    }	
    
 
	//----------------------------------
	// horizontalSpeed
	//----------------------------------
	/**
	 * The horizontal speed.
	 */
	public var horizontalSpeed:int = 32;
	
	//----------------------------------
	// verticalSpeed
	//----------------------------------
	/**
	 * The vertical speed.
	 */
	public var verticalSpeed:int = 16;
	
	///----------------------------------
	// verticalFallingSpeed
	//----------------------------------
	/**
	 * The vertical speed.
	 */
	public var verticalFallingSpeed:int = 128;
	
	
	//----------------------------------
	// frameRate
	//----------------------------------
	/**
	 * The default frame rate for all animations.
	 */
	public var frameRate:int = 8;

    //--------------------------------------------------------------------------
    //
    //  Overridden Methods - FlxSprite
    //
    //--------------------------------------------------------------------------	
    override public function update():void
    {
        if(!onScreen())
            kill();
        super.update();
    } 

    override public function hitRight(Contact:FlxObject, Velocity:Number):void
    {
    }

    override public function hitLeft(Contact:FlxObject, Velocity:Number):void
    {
    }   
    
	//--------------------------------------------------------------------------
	//
	//  Methods
	//
	//--------------------------------------------------------------------------
	
	//----------------------------------
	//  stopMoving
	//----------------------------------
	/**
	 * stops moving the sprite
	 */
	public function stopMoving():void
	{
		play(BaseSprite.STOP_MOVING);
		velocity.x = velocity.y = 0;
        if (_direction != -1)
            _lastDirection = _direction;
        _direction = -1;
	} 
	
	//----------------------------------
	//  moveLeft
	//----------------------------------
	/**
	 * moves the sprite to the left
	 */
	public function moveLeft():void
	{
		play(BaseSprite.MOVE_LEFT);
		velocity.x = -horizontalSpeed;
		velocity.y = 0;
        _direction = FlxSprite.LEFT;
	}
	
	//----------------------------------
	//  moveRight
	//----------------------------------
	/**
	 * moves the sprite to the right
	 */
	public function moveRight():void
	{
		play(BaseSprite.MOVE_RIGHT);
		velocity.x = horizontalSpeed;
		velocity.y = 0;
        _direction = FlxSprite.RIGHT;
	} 
	
	//----------------------------------
	//  moveUp
	//----------------------------------
	/**
	 * moves the sprite up
	 */
	public function moveUp():void
	{
		play(BaseSprite.MOVE_UP);
		velocity.x = 0;
		velocity.y = -verticalSpeed;
        _direction = FlxSprite.UP;
	} 
	
	//----------------------------------
	//  moveDown
	//----------------------------------
	/**
	 * moves the sprite down
	 */
	public function moveDown():void
	{
		play(BaseSprite.MOVE_DOWN);
		velocity.x = 0;
		velocity.y = verticalSpeed;
        _direction = FlxSprite.DOWN;
	} 
	
	//----------------------------------
	//  jump
	//----------------------------------
	/**
	 * makes the sprite jump
	 */
	public function jump():void
	{
        
		velocity.x = velocity.y = 0;
        /*
        if (direction == FlxSprite.LEFT)
            play(BaseSprite.JUMP_LEFT);
        else if (direction == FlxSprite.RIGHT)
            play(BaseSprite.JUMP_RIGHT);
        else
            play(BaseSprite.JUMP_ON_THE_SPOT);
        */
	} 
	
	//----------------------------------
	//  fall
	//----------------------------------
	/**
	 * makes the sprite fall
	 */
	public function fall():void
	{
		play(FALL);
		velocity.y = verticalFallingSpeed;
		velocity.x = 0;
        if (_direction != -1)
            _lastDirection = _direction;
        _direction = -1;
	} 

    //----------------------------------
    //  pauseOnLadder
    //----------------------------------
    /**
     * pauses mario on the ladder
     */
    public function pauseOnLadder():void
    {
        stopMoving();
        play(BaseSprite.PAUSE_ON_LADDER);    
    } 
	
} 
}
